#include "mainwindow.h"
#include "ui_mainwindow.h"
#include"mypushbutton.h"
#include<QDebug>
#include<QTimer>
#include<QSound>
#include"playscene.h"
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{

    ui->setupUi(this);
    setFixedSize(800,800);//配置主场景
    setWindowIcon(QIcon(":/res/sodukuIcon2.jpg"));//设置固定大小
    setWindowTitle("数独");//设置主场景名称
    QSound *startsound=new QSound(":/res/TapButtonSound.wav");//开始按钮音效
    connect(this->ui->actionleave,&QAction::triggered,this,[this](){
       this->close();
    });//退出按钮
    MypushButton*startBtn=new MypushButton(":/res/MenuSceneStartButton.png");
    startBtn->setParent(this);
    startBtn->move(this->width()*0.3-startBtn->width()*0.3,this->width()*0.5);
    chooseScence=new ChooseLevelScene;
    connect(chooseScence,&ChooseLevelScene::chooseSceneBack,this,[=](){
       chooseScence->hide();
        this->show();
    });//返回设置
    connect(startBtn,&QPushButton::clicked,this,[=](){
        startsound->play();//点击发声
        qDebug()<<"点击成功";
        startBtn->zoomdown();
        //startBtn->zoomup();
        //进入到选择场景
        QTimer::singleShot(500,this,[=](){
            chooseScence->show();
            this->hide();//隐藏主场景
            //监听返回信号
        });//延时进入
    });
    MypushButton*introBtn=new MypushButton(":/res/IntroButton.png");
    introBtn->setParent(this);
    introBtn->move(this->width()*0.54-introBtn->width()*0.54,10+this->width()*0.3);
    connect(introBtn,&QPushButton::clicked,[&](){//一定要写ed

        qDebug()<<"点击成功";
        QMessageBox::information(this, tr("游戏玩法"),
        QString(tr("在所有空白处填上数字,每行,每列以及每个九宫格内都没有重复数字")));

    });
    MypushButton*configButoon=new MypushButton(":/res/ConfigButton.png");
    configButoon->setParent(this);
    configButoon->move(this->width()*0.75-introBtn->width()*0.75,10+this->width()*0.48);
    connect(configButoon,&QPushButton::clicked,[&](){//一定要写ed
        qDebug()<<"点击成功";


            QString str=QString("您选择了第 %1 关").arg(16);
            qDebug()<<str;
            PlayScene *play=new PlayScene(17);
            play->show();
            this->hide();
            connect(play,&PlayScene::chooseSceneBack,[&](){
                qDebug()<<"has get the chooseSceneBack";
                this->show();

            });
    });
}
void MainWindow::paintEvent(QPaintEvent *){
    QPixmap BackGroundPic;
    BackGroundPic.load(":/res/FirstPic.png");
    BackGroundPic=BackGroundPic.scaled(BackGroundPic.width()*0.9,BackGroundPic.height()*0.9);
    QPainter painter(this);
    painter.drawPixmap(0,0,this->width(),this->height(),BackGroundPic);



};
MainWindow::~MainWindow()
{
    delete ui;
}

